package com.xuecheng.auth.service.checkutils;

import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;

public class CheckInsertResultUtil {
    public static void check(int result, Supplier<RuntimeException> exceptionSupplier) {
        if (result == 0) {
            throw exceptionSupplier.get();
        }
    }

    public static void checkBoolean(Boolean result, Supplier<RuntimeException> exceptionSupplier) {
        if (result) {
            throw exceptionSupplier.get();
        }
    }


    public static <T> T checkExist(T obj, Supplier<RuntimeException> exceptionSupplier) {
        if (obj == null) {
            throw exceptionSupplier.get();
        }
        return obj;
    }

    public static void checkListExist(Supplier<RuntimeException> exceptionSupplier, Object... objects) {
        if (objects == null || objects.length == 0) {
            throw exceptionSupplier.get();
        }

        for (Object obj : objects) {
            if (obj == null) {
                throw exceptionSupplier.get();
            }
        }
    }
}
